package com.lsh.bio;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author ：LiuShihao
 * @date ：Created in 2021/2/22 1:46 下午
 * @desc ： Netty权威指南
 *
 * 同步阻塞式I/O创建的TimeServer源码
 */
public class TimeServer {

    public static void main(String[] args) throws IOException {
        int port = 8888;
        ServerSocket server = null;
        try{
            server = new ServerSocket(port);
            System.out.println("The time server is start in port:"+port);
            Socket socket = null;
            while (true){
                socket = server.accept();
                new Thread(new TimeServerHandler(socket)).start();
            }

        } finally {
            if (server != null){
                System.out.println("The time server close");
                server.close();
                server = null;
            }
        }

    }
}
